#cs
	Shizuha Version 1.0.0.2
	Senkom Mitra Polri eQSO Scheduler

	@author Julot <andy.julot@gmail.com>
	@since Thursday, May 10, 2012. 10:17 AM

	History:
	0.0.0.0: 2012-05-11
	1.0.0.0: 2012-05-11
	1.0.0.1: 2012-05-12
	1.0.0.2: 2012-05-16

	Cron.txt
	# Use cron format
	# http://en.wikipedia.org/wiki/Cron
	# minute hour day month weekday command
	# valid command: connect|disconnect|room [room]

	Example content of Shizuha.ini

	[Connect]
	# Deprecated. Use Cron.txt instead
	# Valid entry is [#]=[time]
	# Example:
	#   1=08:00:00
	#   2=09:00:00
	1=14:05:00
	2=14:05:10

	[Disconnect]
	# Deprecated. Use Cron.txt instead
	# @see Connect
	1=14:05:20

	[ChangeRoom]
	# Deprecated. Use Cron.txt instead
	# Valid entry is [#]=[time] [room name]
	# Example:
	#   1=08:00:00 RoomA
	#   2=09:00:00 RoomB
	1=14:05:30 AutoIt
#ce

#include <AutoitObject.au3>
#include <Eqso.au3>

Func readIni($section)
	$sections = IniReadSection('Setting.ini', $section)
	If $sections == 1 Or @error == 1 Then
		Return False
	Else
		Return $sections
	EndIf
EndFunc   ;==>readIni

Func main()
	_AutoItObject_StartUp()

	$eqso = Eqso()

	If Not $eqso.exist() Then
		$s = 'Program eQSO harus dijalankan terlebih dahulu.'
		$s &= @CRLF
		$s &= 'Gunakanlah eQSO versi Senkom Mitra Polri Pusat.'
		MsgBox(48, 'eQSO belum aktif', $s)
		Return
	EndIf

	$connects = readIni('Connect')
	$disconnects = readIni('Disconnect')
	$changeRooms = readIni('ChangeRoom')

	While 1
		$now = @HOUR & ':' & @MIN & ':' & @SEC
		If $connects <> False Then
			For $i = 1 To $connects[0][0]
				If $connects[$i][1] == $now Then
					$eqso.connect()
				EndIf
			Next
		EndIf

		If $disconnects <> False Then
			For $i = 1 To $disconnects[0][0]
				If $disconnects[$i][1] == $now Then
					$eqso.disconnect()
				EndIf
			Next
		EndIf

		If $changeRooms <> False Then
			For $i = 1 To $changeRooms[0][0]
				$values = StringSplit($changeRooms[$i][1], ' ')
				If $values[0] == 2 Then
					If $values[1] == $now Then
						$eqso.changeRoom($values[2])
					EndIf
				EndIf
			Next
		EndIf

		Sleep(500)
	WEnd
EndFunc   ;==>main

main()
